#include "Dx11DemoBase.h"
//#include "WICTextureLoader.h"
//#include "DDSTextureLoader.h"
#include "Camera.h"


Dx11DemoBase::Dx11DemoBase()
{
	Pos = XMFLOAT3(0.f, 0.f, 0.f);
	Rotation = XMFLOAT3(0.f, 0.f, 0.f);
}


Dx11DemoBase::~Dx11DemoBase()
{
	UnLoadContent();
}

bool Dx11DemoBase::LoadContent()
{
	return true;
}

void Dx11DemoBase::UnLoadContent()
{

}

HRESULT WINAPI Dx11DemoBase::DXUTCreateShaderResourceViewFromFile(_In_ ID3D11Device* d3dDevice, _In_z_ const wchar_t* szFileName, _Outptr_ ID3D11ShaderResourceView** textureView)
{
	if (!d3dDevice || !szFileName || !textureView)
		return E_INVALIDARG;

	HRESULT hr;

	WCHAR ext[_MAX_EXT];
	_wsplitpath_s(szFileName, nullptr, 0, nullptr, 0, nullptr, 0, ext, _MAX_EXT);
	hr = DirectX::CreateWICTextureFromFile(d3dDevice, nullptr, szFileName, nullptr, textureView);

	return hr;
}

void Dx11DemoBase::SetTheCamera(class Camera* InCamera)
{
	TheCamera = InCamera;
}

void Dx11DemoBase::SetPos(XMFLOAT3 InPos)
{
	Pos = InPos;
}

bool Dx11DemoBase::CompileD3DShader(TCHAR* filePath, char* entry, char* shaderModel, ID3DBlob** buffer)
{
	DWORD shaderFlags = D3DCOMPILE_ENABLE_STRICTNESS;
#if defined _DEBUG || defined DEBUG
	shaderFlags = D3DCOMPILE_DEBUG;
	shaderFlags |= D3DCOMPILE_SKIP_OPTIMIZATION;
#endif

	ID3DBlob *errorBuffer = 0;
	HRESULT result;
	result = D3DCompileFromFile(filePath, 0, 0, entry, shaderModel, shaderFlags,  0, buffer, &errorBuffer);
	if (FAILED(result))
	{
		if (errorBuffer != 0)
		{
			OutputDebugStringA((char*)errorBuffer->GetBufferPointer());
			errorBuffer->Release();
		}
		return false;
	}

	if (errorBuffer != 0)
	{
		return false;
	}

	return true;
}
